<template>
    <transition>
        <div class="content">
            <div class="fingerprint-login"><img src="@/assets/img/4.png" alt=""></div>
            <div class="fingerprint-img"><img src="@/assets/img/fingerprint.png" alt="" @click="fingerPrint()"></div>
            <div class="fingerprint-click" @click="fingerPrint()">{{ $t('m.common.touch.listTitle') }}</div>
            <!--<div class="fingerprint-wallet">使用钱包密码登录</div>-->
        </div>
    </transition>
</template>
<script>
    /* eslint-disable */
    export default {
        name: 'touch',
        created() {
            this.fingerPrint();
        },
        mounted() {

        },
        data() {
            return {}
        },
        methods: {
            fingerPrint() {
                let that = this;
                let check = this.checkSupport();
                if (check == 1) {
                    plus.device.vibrate();
                    plus.fingerprint.authenticate(function () {
                        plus.nativeUI.closeWaiting();//兼容Android平台关闭等待框
                        that.changeRoute("/index/wallet");
                    }, function (e) {
                        if ('Android' === plus.os.name) {
                            plus.device.vibrate();
                        }
                        switch (e.code) {
                            case e.AUTHENTICATE_MISMATCH:
                                break;
                            case e.AUTHENTICATE_OVERLIMIT:
                                plus.nativeUI.closeWaiting();//兼容Android平台关闭等待框
                                plus.nativeUI.alert(this.$t('m.common.touch.prompt[0]'));
                                break;
                            default:
                                plus.nativeUI.closeWaiting();//兼容Android平台关闭等待框
                                break;
                        }
                    });
                    // Android平台弹出等待提示框
                    if ('Android' === plus.os.name) {
                        plus.nativeUI.showWaiting(this.$t('m.common.touch.prompt[1]'));
                    }
                } else if (check == 2) {
                    // 还没准备好，200后重新执行
                    setTimeout(() => {
                        this.fingerPrint();
                    }, 200);
                } else {
                    this.changeRoute('/index/wallet');
                }
            },
            checkSupport: function () {
                // 当没有检测到plus对象的时候，等待500ms
                if (typeof plus != 'undefined') {
                    if (plus.fingerprint) {
                        if (!plus.fingerprint.isSupport()) {
                            // result.innerText = '此设备不支持指纹识别';
                            console.log("此设备不支持指纹识别");
                            return 0;
                        }
                        if (!plus.fingerprint.isKeyguardSecure()) {
                            // result.innerText = '此设备未设置密码锁屏，无法使用指纹识别';
                            console.log("此设备未设置密码锁屏，无法使用指纹识别");

                            return 0;
                        }
                        if (!plus.fingerprint.isEnrolledFingerprints()) {
                            // result.innerText = '此设备未录入指纹，请到设置中开启';
                            console.log("此设备未录入指纹，请到设置中开启");
                            return 0;
                        }
                        // result.innerText = '此设备支持指纹识别';
                        return 1;
                    } else {
                        // result.innerText = '当前环境不支持指纹识别API，请更新到最新版本';
                        console.log("此设备未录入指纹，请到设置中开启");
                        return 0;
                    }
                } else {
                    return 2;
                }

            }
        }
    }
</script>
<style scoped>
    @import '../../assets/css/fingerprintLogin.css';

</style>